package com.fjec.market.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjec.market.entity.InfoSku;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 012.商品sku表 Mapper 接口
 * </p>
 *
 * @author admin
 * @since 2020-09-10
 */
public interface InfoSkuMapper extends BaseMapper<InfoSku> {
    @SelectProvider(type = com.fjec.market.mapper.sqlbuilder.SkuSqlBuilder.class, method = "getTop2SkusByBusiIds")
    List<Map<String, Object>> getTop2SkusByBusiIds(@Param("farmerIds") List<Long> farmerIds);

    @SelectProvider(type = com.fjec.market.mapper.sqlbuilder.SkuSqlBuilder.class, method = "getSkusByBusiIds")
    List<Map<String, Object>> getSkusByBusiIds(@Param("farmerIds") List<Long> farmerIds);

    @SelectProvider(type = com.fjec.market.mapper.sqlbuilder.SkuSqlBuilder.class, method = "getSkusBySpuIDsAndMarkCodeAndBusiType")
    List<Map<String, Object>> getSkusBySpuIDsAndMarkCodeAndBusiType(@Param("markCode") int markCode, @Param("busiType") int busiType,
                                                                    @Param("spuIds") List<Long> spuIds, @Param("orderBy") int orderBy,
                                                                    @Param("dir") int dir, Page page);

    /**
     * 根据skuId列表查询商品信息，生成订单用
     *
     * @param skuIdList
     * @return
     */
    List<Map<String, Object>> getSkuInfoByIdList(@Param("skuIdList") List<Long> skuIdList);

    Map<String, Object> getSkuById(Long id, Long userId);

    @Select("select ifnull(sum(SaleNum), 0) from (select SaleNum from info_sku where BusiId = #{id}) tmp")
    Integer sumSkuSaleNumByBusiId(@Param("id") Long id);

    /**
     * 获取用户收藏sku列表
     *
     * @param userId
     * @return
     */
    Page<Map<String, Object>> getFavoInfoSkuList(@Param("page") Page page,
                                                 @Param("userId") Long userId);

    @SelectProvider(type = com.fjec.market.mapper.sqlbuilder.SkuSqlBuilder.class, method = "getRetailFruits")
    List<Map<String, Object>> getRetailFruits(@Param("markCode") Integer markCode,
                                              @Param("spuIds") List<Long> spuIds,
                                              @Param("orderBy") Integer orderBy,
                                              @Param("dir") Integer dir,
                                              Page page);

    /**
     *
     * @return
     */
    Long tmpUpdateSaleNum();
}
